fix: prevent wrong results from Iceberg native scan exchange reuse with different pushed filters - #4812
Merged
Merged
Conversation
Contributor
Author
|
@sandugood are you able to test with this branch? Thanks again for reporting the issue! |
Contributor
|
Going to test it right now, thanks for quick response! |
andygrove
reviewed
Jul 3, 2026
andygrove
approved these changes
Jul 3, 2026
andygrove
left a comment
Member
There was a problem hiding this comment.
LGTM pending CI. Thanks @mbutrovich
Contributor
|
Tested against this branch on the same pipeline. Got same exact results for both default Spark and Spark+Comet. Thanks for a great fix, @mbutrovich |
Contributor
Author
Great to hear! Thank you for confirming and the quick correspondence while working these issues. |
This was referenced Jul 6, 2026
mbutrovich
added a commit
that referenced
this pull request
Jul 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #4774.
Rationale for this change
Comet silently produces wrong results when the same Iceberg table is scanned more than once with different pushed-down filters (for example a
FULL OUTER JOINorUNION ALLof two differently-filtered reads). Spark's non-AQEReuseExchangeAndSubquerykeys exchange reuse offExchange.canonicalized, which delegates to the scan's canonical form.CometIcebergNativeScanExec.equals/hashCode/doCanonicalizeidentified a scan bymetadataLocation,output,serializedPlanOpt, andruntimeFiltersonly. None of these carry the pushed static filters, which live in the@transient originalPlanthat canonicalization nulls out. Two scans of the same table+snapshot with different filters therefore canonicalize identically, and reuse collapses them into one, so one branch reads the other branch's data.Vanilla Spark avoids this because
BatchScanExec.equalscomparesscan.toBatch, and Iceberg'sSparkBatch.equalscomparestable.name()plusSparkScan.hashCode(), which folds in pushed filters, snapshot, branch, and read schema. Spark also keeps thescanreference alive throughdoCanonicalize, so the fingerprint survives. Comet's V1 Parquet scan (CometNativeScanExec) is not affected because its filters are top-levelpartitionFilters/dataFiltersfields that are already in equality and preserved by canonicalization.What changes are included in this PR?
scanHashCode: Intfield toCometIcebergNativeScanExec, captured fromscanExec.scan.hashCode()in theapplyfactory while the transient scan is still available.scanHashCodeinequalsandhashCode, and carry it throughdoCanonicalize(it is the only distinguishing field left onceoriginalPlanis nulled) andconvertBlock.How are these changes tested?
New test in
CometIcebergNativeSuite: "exchange reuse must not collapse scans with different pushed filters (#4774)". It runs aUNION ALLof two aggregations over the same partitioned Iceberg table with different partition filters under non-AQE withspark.sql.exchange.reuse=true. It fails onmain(branch B reuses branch A's exchange, yielding A twice and dropping B) and passes with this change. BeyondcheckSparkAnswerAndOperator, it asserts bothCometIcebergNativeScanExecnodes survive and that noReusedExchangeExeccollapsed the branches. The existing AQE DPP broadcast-reuse tests continue to pass, confirming legitimate reuse (identical scans still share an exchange) is preserved.